Count Property (Messages Collection) 

The Count property returns the number of MessageC062VO objects in the collection, or a very large number if the exact count is not available. Read-only.

Syntax

objMsgColl.Count

Data Type

Long

Remarks

The Count property is useful for determining whether a Messages collection is empty or not.

A large collection cannot always maintain an accurate count of its members, and the Count property cannot be used as the collection s size when it has a very large value such as mapiMaxCount. Programmers needing to access individual objects in a large collection are strongly advised to use the Visual Basic For Each statement or the Get methods.

The recommended procedures for traversing a large collection are, in decreasing order of preference:

  1.  Global selection, such as the Visual Basic For Each statement

  2.  The Get methods, particularly GetFirst9__LKW and GetNext32T8DG

  3.  An indexed loop, such as the Visual Basic For ... Next construction

If the message store provider cannot supply the precise number of Message objects, the OLE Messaging Library returns a very large number for the Count property. On 32-bit platforms, this value is mapiMaxCount, which equals 2^31 - 1, or 2147483647. On other platforms, mapiMaxCount is not defined, and the OLE Messaging Library returns -1. A program on such a platform must be careful that -1 does not prematurely terminate any iteration based on the Count property.

Programmers using an indexed loop terminating on the Count property must also check each returned object for a value of Nothing. The loop must proceed forward from the beginning of the collection, and the index must have initial and increment values of 1. Results are undefined for any other procedure.

The use of the Item1RHMKS5 property in conjunction with the Count property in a large collection can be seen in the following example.

Example

This code fragment searches for a Mesage object with subject  Bonus :

Dim i As Integer ' loop index / object counter

Dim collMessages as Object ' Messages collection; assume already given

If collMessages Is Nothing Then

    ' MsgBox "Messages collection object is invalid"

    ' Exit

End If

' see if collection is empty

If 0 = collMessages.Count Then

    ' MsgBox "No messages in collection"

    ' Exit

End If

' look for message about  Bonus  in collection

For i = 1 To collMessages.Count Step 1

    If collMessages.Item(i) Is Nothing Then

    ' MsgBox "No such message found in collection"

    ' Exit ' no more messages in collection

    End If

    If collMessages.Item(i).Subject =  Bonus  Then

    ' MsgBox "Desired message is at index " & i

    ' Exit

    End If

Next i